


import axios from '../handleService'

export default {
  // createNotebook: params => axios.post('/api/file', params),
  // renameNotebook: params => axios.put('/api/file', params),
  cloneNotebook: params => axios.post('/api/file/clone', params),
  // delNotebook: ({ id, type }) => axios.delete(`/api/file/${id}?type=${type}`),
  // saveOpenedNotebook: list => axios.put('/api/files/opened', list),
  // getOpenedNotebook: () => axios.get('/api/files/opened'),
  importNotebook: data => axios.post('/api/file/import', data, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  }),
  // moveNotebook: data => axios.post('/api/file/move', data),
  excuteCode: params => axios.post('/api/api-manage/test', params),
  getJobStatus: id => axios.get(`/api/job/${id}`),
  saveNotebookById: ({ id, data }) => axios.put(`/api/notebook/${id}`, data),
  getNotebookById: (id, commit_id) => axios.get(`/api/notebook/${id}${commit_id ? '?commit_id=' + commit_id : ''}`),
  // cancelExcuteCell: id => axios.post(`/api/job/${id}/cancel`),
  getExcuteProcess: id => axios.get(`/api/job/${id}/progress`),
  getCurrentScript: id => axios.get(`/api/job/${id}/current_script`),
  createCell: ({ id, data }) => axios.post(`/api/notebook/${id}/cell`, data),
  deleteCell: ({ id, cell_id }) => axios.delete(`/api/notebook/${id}/cell/${cell_id}`),
  getDefaultNotebook: () => axios.get('/api/notebook/default'),
  clearAllResults: notebookId => axios.delete(`/api/notebook/${notebookId}/result`),
  // moveFolder: data => axios.post('/api/folder/move', data),
  // renameFolder: data => axios.put('/api/folder', data),
  cloneFolder: data => axios.post('/api/folder/clone', data),
  // deleteFolder: id => axios.delete(`/api/folder/${id}`),
  autoComplete: params => axios.post('/api/notebook/code/suggestion', params),
  exportNotebook: ({ type, id, output }) => axios.get(`/api/file/export/${id}?type=${type}${output ? '&output=' + output : ''}`, { responseType: 'blob' }),
  setDemo: params => axios.post('/api/settings/demo', params),
  offlineDemo: params => axios.post('/api/settings/demo/remove', params),

  // 新建文件夹
  createFolder: data => axios.post('/api/folder/', data),
  // 重命名文件夹
  renameFolder: ({ id, params }) => axios.put(`/api/folder/${id}`, params),
  // 获取目录树
  getNotebookList: projectId => axios.get(`/api/folder/tree?projectId=${projectId}`),
  // 移动文件夹
  moveFolder: ({ id, params }) => axios.put(`/api/folder/${id}/move`, params),
  // 删除文件夹
  deleteFolder: id => axios.delete(`/api/folder/${id}`),

  // 新建工作流
  createNotebook: params => axios.post('/api/workflow/', params),
  // 重命名工作流
  renameNotebook: ({ id, params }) => axios.put(`/api/workflow/${id}`, params),
  // 移动工作流
  moveNotebook: ({ id, params }) => axios.put(`/api/workflow/${id}/move`, params),
  // 删除工作流
  delNotebook: id => axios.delete(`/api/workflow/${id}`),
  // 已经打开的工作流 
  getOpenedNotebook: id => axios.get(`/api/workflow/opened/?projectId=${id}`),
  // 记录打开的工作流
  saveOpenedNotebook: params => axios.post('/api/workflow/opened/', params),

  // 停止任务
  cancelExcuteCell: id => axios.put(`/api/job/${id}/cancel`),
}
